package com.example.floatingpopulation.controller;

import com.example.floatingpopulation.common.Result;
import com.example.floatingpopulation.controller.request.CommunityAssistancePageRequest;
import com.example.floatingpopulation.controller.request.JurisdictionalUnitPageRequest;
import com.example.floatingpopulation.entity.CommunityAssistance;
import com.example.floatingpopulation.service.CommunityAssistanceService;
import com.example.floatingpopulation.service.JurisdictionalUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/communityAssistance")
public class CommunityAssistanceController {
    @Autowired
    CommunityAssistanceService communityAssistanceService;


    @PostMapping("/save")
    public Result<String> save(@RequestBody CommunityAssistance obj) {
        communityAssistanceService.save(obj);
        return Result.success();
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody CommunityAssistance obj) {
        communityAssistanceService.update(obj);
        return Result.success();
    }

    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody CommunityAssistance obj) {
        communityAssistanceService.updateStatus(obj);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Integer id){
        communityAssistanceService.deleteById(id);
        return Result.success();
    }


    @GetMapping("/list")
    public Result<String> list(){
        List<CommunityAssistance> list = communityAssistanceService.list();
        return Result.success(list);
    }


    @GetMapping("/page")
    public Result<String> page(CommunityAssistancePageRequest pageRequest){
        return Result.success(communityAssistanceService.page(pageRequest));
    }

}
